---
layout: "default"
title: "CVarArgType"
description: "Swift documentation for 'CVarArgType': Instances of conforming types can be encoded, and appropriately."
keywords: "CVarArgType,protocol,swift,documentation,encode"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">protocol CVarArgType</code></div>

<div class="discussion comment">
    <p>Instances of conforming types can be encoded, and appropriately
passed, as elements of a C <code>va_list</code>.</p>

<p>This protocol is useful in presenting C &quot;varargs&quot; APIs natively in
Swift.  It only works for APIs that have a <code>va_list</code> variant, so
for example, it isn&#39;t much use if all you have is:</p>

<pre><code class="language-swift">int f(int n, ...)</code></pre>

<p>Given a version like this, though, :</p>

<pre><code class="language-swift">int f(int, va_list arguments)</code></pre>

<p>you can write:</p>

<pre><code class="language-swift">func swiftF(x: Int, arguments: CVarArgType...) -&gt; Int {
  return withVaList(arguments) { f(x, $0) }
}</code></pre>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>







<h3>Instance Methods</h3>
<div class="declaration" id="func-encode">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-encode">func encode()</a>
     <span class="required">Required</span>    
<div class="comment collapse" id="comment-func-encode"><div class="p">
    <p>Transform <code>self</code> into a series of machine words that can be
appropriately interpreted by C varargs</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func encode() -&gt; [Word]</code>
    
    
</div></div>
</div>


